cc.Class({
    extends: cc.Component,

    properties: {
        label: {
            default: null,
            type: cc.Label
        },
        targetSprite: {
            default: null,
            type: cc.Sprite
        },
        shot: cc.Sprite,
        text: 'Hello, World!'
    },

    onLoad: function () {
        this.label.string = this.text;
        this.screenshot = this.node.addComponent('Screenshot');
    },

    onBtn_node_native() {
        if (cc.sys.isNative ) {
            var targetNode = this.targetSprite.node;
            this.screenshot.screenshotNative('node_native.png', false,targetNode, frame => {
                // 截取有效部分
                var size = cc.director.getWinSize();
                var targetNodeSize = cc.size(targetNode.width, targetNode.height);
                let spriteFrame=this.screenshot.cutPicture(frame,cc.rect((size.width - targetNodeSize.width)/2,(size.height - targetNodeSize.height)/2 ,targetNodeSize.width,targetNodeSize.height));
                this.shot.spriteFrame = spriteFrame;
            });
        } else {
            this.label.string ='is not Native';
        }
    },

    onBtn_native() {
        if (cc.sys.isNative ) {
            this.screenshot.screenshotNative('native.png', false, null, frame => {
                this.shot.spriteFrame = frame;
            });
        } else {
            this.label.string = 'is not Native';
        }
    },

    onbtn_web() {
        if (cc.sys.isBrowser) {
            this.screenshot.screenshotWebGL(frame => {
                this.shot.spriteFrame = frame;
            });
        }else {
            this.label.string = 'is not Browser';
        }
    },

    onbtn_canvas() {
        if(cc.sys.isBrowser) {
            this.screenshot.screenshotCanvas(frame => {
                this.shot.spriteFrame = frame;
            });
        }else {
            this.label.string = 'is not Browser';
        }
    },

});
